from tools.initialization_config import *
from watson_developer_cloud import LanguageTranslatorV2 as LanguageTranslator


class IBMTranslateRecognizer(object):
    def __init__(self):
        self.cuid = get_mac_address()
        self.username, self.password = self.get_ibm_api_config()

    def get_ibm_api_config(self):
        _CONF_PATH = 'translate/ibm/IBMOAuth.ini'
        ini_parser = InitializationConfigParser(_CONF_PATH)
        client_credentials = ini_parser.GetAllNodeItems("ClientCredentials")
        username = client_credentials.get("username")
        password = client_credentials.get("password")
        return username, password

    def translate_text(self, text):
        language_translator = LanguageTranslator(username=self.username, password=self.password)
        translate = language_translator.translate(text, model_id='zh-en-patent', source='en', target='zh')
        return translate